package com.heima;

import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * Hello world!
 *
 */
public class App 
{

    public static void main( String[] args )
    {

        // 获取io流
        try {
            FileInputStream fileInputStream = new FileInputStream("D:\\list.html");

            MinioClient minioClient = MinioClient
                    .builder()
                    .credentials("minio","minio123") // 指定minio的账号密码
                    .endpoint("http://192.168.200.130:9000") // 指定minio的路径
                    .build(); // 创建一个MinIO的客户端

            // 存入minIO中
            PutObjectArgs putObjectArgs = PutObjectArgs
                    .builder()
                    .object("list.html")
                    .bucket("leadnews") // 指定minIO的桶
                    .contentType("text/html") // 指定文章格式
                    .stream(fileInputStream, fileInputStream.available(), -1) // 指定读取(只要文件有空闲就完全存入)
                    .build();
            minioClient.putObject(putObjectArgs);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
